<template >
    <div class="body">
      <div class="content">
        <div class="login-wrapper">
          <div class="left-img">
            <div class="glass">
              <div class="tips">
                <div class="title">
                  THE SPACE NETWORK
                </div>
                <h1>Explore The Universe</h1>
                <span>5 Million+ people have joined our network.</span>
                <span>we invite you to join the tribe</span>
              </div>
            </div>
          </div>
          <div class="right-login-form">
            <el-form
                ref="ruleFormRef"
                id="form"
                :model="ruleForm"
                :rules="rules"
                label-width="auto"
                class="demo-ruleForm"
            >
              <h1 style="width: 100%;text-align: center;padding-bottom: 50px" >登录</h1>
              <span>工号</span>
              <el-form-item  prop="staffNo" style="padding-bottom: 20px">
                <el-input
                    v-model="ruleForm.staffNo"
                />
              </el-form-item>
              <span>密码</span>
              <el-form-item prop="password" style="padding-bottom: 20px">
                <el-input v-model="ruleForm.password" type="password" @keyup.enter="submitForm(ruleFormRef)" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="submitForm(ruleFormRef)" style="width: 300px;background-color: rgb(128, 113, 198)">
                  登录
                </el-button>
              </el-form-item>
              <el-form-item>
                <el-button @click="resetForm(ruleFormRef)" style="width: 300px">重置</el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
      </div>
    </div>
</template>

<script  setup>
import { reactive, ref } from 'vue'
import {ElMessage} from 'element-plus'
import router from '@/router';
import axiosInstance from "@/axios/index.js";
import {useStaffStaffStore} from "@/stores/staff.js";
const ruleFormRef = ref()

const ruleForm = reactive({
  staffNo: '',
  password: '',
})

const rules = reactive({
  staffNo:[{ required: true, message: '请输入工号ID', trigger: 'blur',}],
  password:[{ required: true, message: '请输入用户密码', trigger: 'blur',}],
})

const submitForm = (formEl) => {
  if (!formEl) return
   formEl.validate ((valid) => {
    if (valid) {
        axiosInstance.post("/staff/login",{
          staffNo: ruleForm.staffNo,
          password: ruleForm.password,
        }).then(res =>{
          localStorage.setItem("token", res.data.data);
          useStaffStaffStore().getStaffInfo(ruleForm.staffNo)
          ElMessage({
            message: '登录成功',
            type: 'success',
            duration: 500,
            onClose: function (){
              useStaffStaffStore().staffInfo.staff.isFirstLogin==1
              ?router.push("/staffInfo")
              :router.push("/index")
            }
          })
        })
    } else {
      ElMessage({
        message: '不满足表单规则!请检查一下',
        type: 'error',
      })
    }
  })
}

const resetForm = (formEl) => {
  if (!formEl) return
  formEl.resetFields()
}
</script>

<style scoped>
  .body{
    width: 100%;
    height: 100%;
    background-repeat: no-repeat;
    background-size: cover; /* 或 100% 100% */
  }
  #form{
    width: 300px;
    margin: 0 auto;
    position:relative;
    top: 100px;
    padding: 40px 40px 60px 20px;
    background-color: white;
    opacity:0.8;
  }
  .content {
    width: 100vw;
    height: 100vh;
    position: relative;
  }
  .content .login-wrapper {
    width: 70vw;
    height: 80vh;
    background-color: #fff;
    border-radius: 40px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: flex;
  }
  .content .login-wrapper .left-img {
    border-radius: 40px;
    flex: 1;
    background: url(@/assets/images/img.png) no-repeat;
    background-size: cover;
    position: relative;
  }
  .content .login-wrapper .left-img .glass {
    width: 60%;
    padding: 20px;
    color: #fff;
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translate(-50%, -20%);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, 0.48);
  }
  .content .login-wrapper .left-img .glass .tips .title {
    width: 25%;
    font-weight: 600;
    font-size: 15px;
    text-align: center;
    padding: 10px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, 0.48);
  }
  .content .login-wrapper .left-img .glass .tips h1 {
    margin: 15px 0;
  }
  .content .login-wrapper .left-img .glass .tips span {
    margin: 5px 0;
    display: block;
    font-weight: 100;
  }
  .content .login-wrapper .right-login-form {
    flex: 1;
    position: relative;
  }
  .content .login-wrapper .right-login-form .form-wrapper {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
  .content .login-wrapper .right-login-form .form-wrapper h1 {
    font-size: 30px;
    text-align: center;
  }
  .content .login-wrapper .right-login-form .form-wrapper .input-items {
    margin: 20px 0;
  }
  .content .login-wrapper .right-login-form .form-wrapper .input-items .input-tips {
    display: inline-block;
    font-weight: 600;
    font-size: 20px;
    margin: 10px 0;
  }
  .content .login-wrapper .right-login-form .form-wrapper .input-items .inputs {
    width: 100%;
    height: 50px;
    border-radius: 10px;
    border: 1px solid rgb(227, 227, 227);
    padding: 20px;
    box-sizing: border-box;
    outline: none;
    transition: 0.5s;
  }
  .content .login-wrapper .right-login-form .form-wrapper .input-items .inputs:focus {
    border: 1px solid rgb(128, 106, 196);
  }
  .content .login-wrapper .right-login-form .form-wrapper .input-items .forgot {
    float: right;
    font-weight: 600;
    text-align: right;
    margin: 5px 0;
    font-size: 13px;
    cursor: pointer;
  }
  .content .login-wrapper .right-login-form .form-wrapper .btn {
    width: 100%;
    height: 50px;
    background-color: rgb(128, 106, 196);
    border: 0;
    border-radius: 10px;
    color: #fff;
    font-size: 25px;
    margin: 20px 0;
    cursor: pointer;
  }
  .content .login-wrapper .right-login-form .form-wrapper .siginup-tips {
    text-align: center;
    font-weight: 600;
    margin: 10px 0;
  }
  .content .login-wrapper .right-login-form .form-wrapper .siginup-tips span:last-child {
    color: rgb(110, 87, 179);
    cursor: pointer;
  }
  .content .login-wrapper .right-login-form .form-wrapper .other-login .divider {
    width: 100%;
    margin: 20px 0;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .content .login-wrapper .right-login-form .form-wrapper .other-login .divider .line {
    display: inline-block;
    max-width: 35%;
    width: 35%;
    flex: 1;
    height: 1px;
    background-color: rgb(162, 172, 185);
  }
  .content .login-wrapper .right-login-form .form-wrapper .other-login .divider .divider-text {
    vertical-align: middle;
    margin: 0 20px;
    display: inline-block;
    width: 50px;
    color: rgb(162, 172, 185);
    white-space: normal;
  }
  .content .login-wrapper .right-login-form .form-wrapper .other-login .other-login-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .content .login-wrapper .right-login-form .form-wrapper .other-login .other-login-wrapper .other-login-item {
    width: 70px;
    padding: 10px;
    text-align: center;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    color: rgb(51, 49, 116);
    margin: 0 10px;
    transition: 0.4s;
  }
  .content .login-wrapper .right-login-form .form-wrapper .other-login .other-login-wrapper .other-login-item img {
    width: 40px;
    height: 40px;
    vertical-align: middle;
  }
  .content .login-wrapper .right-login-form .form-wrapper .other-login .other-login-wrapper .other-login-item span {
    vertical-align: middle;
  }
  .content .login-wrapper .right-login-form .form-wrapper .other-login .other-login-wrapper .other-login-item:hover {
    width: 80px;
    height: 50%;
    background-color: #fff;
    border: 0;
    box-shadow: 1px 10px 32px 1px rgba(186, 175, 221, 0.37);
  }

  @media (max-width: 1024px) {
    .login-wrapper {
      padding: 20px;
    }
    .login-wrapper .left-img {
      display: none;
    }
    .login-wrapper .right-login-form {
      padding: 20px;
    }
  }
</style>
